local yechou = fk.CreateSkill{
    name = "heg__yechou",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
    ["heg__yechou"] = "业仇",
    [":heg__yechou"] = "锁定技，你死亡时，视为对杀死你的角色依次使用三张无距离限制的【杀】，其中：第一张不能被响应，第二张无视目标角色的防具，第三张造成的伤害+1。"..
    "若其以此法进入濒死状态，与其势力相同的其他角色不能对其使用【桃】。",

    ["#heg__yechou-use"] = "业仇：视为对%src使用无距离限制的【杀】",
    ["$heg__yechou1"] =  "孙策小儿，你必还恶报！",
    ["$heg__yechou2"] = "吾命丧黄泉，你也休想得安!",
}

local H = require "packages.ol_hegemony.util"

yechou:addEffect(fk.Death,{
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
       return target == player and player:hasSkill(yechou.name, false, true) and data.damage and data.damage.from and not data.damage.from.dead
       and player:canUseTo(Fk:cloneCard("slash"), data.damage.from, {bypass_times = true, bypass_distances = true})
    end,
    on_use = function (self, event, target, player, data)
       local room = player.room
       local from = data.damage.from
       --第一张不可响应
       if from and not from.dead then
        room:setPlayerMark(player, "heg__yechou-target", from.id)
        --不可被响应
        local card1 = Fk:cloneCard("slash")
        card1.skillName = yechou.name
        local use1 = {
        from = player,
        tos = { from } ,
        card = card1,
        extraUse = true,
        extra_data = { bypass_distances = true, bypass_times = true, heg__yechoutarget = from.id},
        disresponsiveList = room.alive_players,
        }
        if player:canUseTo(card1, from, { bypass_distances = true, bypass_times = true}) then
         room:useCard(use1)
        end
        --无视防具
        if from.dead then return true end
        local card2 = Fk:cloneCard("slash")
        card2.skillName = yechou.name
        local use2 = {
        from = player,
        tos = { from } ,
        card = card2,
        extraUse = true,
        extra_data = { bypass_distances = true, bypass_times = true, heg__yechoutarget = from.id, qinggang = true},
        }
       if player:canUseTo(card2, from, { bypass_distances = true, bypass_times = true}) then
        room:useCard(use2)
        end
        if from.dead then return end
        local card3 = Fk:cloneCard("slash")
        card3.skillName = yechou.name
        local use3 = {
          from = player,
          tos =  { from } ,
          card = card3,
          extraUse = true,
          extra_data = { bypass_distances = true, bypass_times = true, heg__yechoutarget = from.id},
          additionalDamage = 1,
        }
        if player:canUseTo(card3, from, { bypass_distances = true, bypass_times = true}) then
          room:useCard(use3)
        end
      end
    end,
})

yechou:addEffect(fk.EnterDying,{
    can_refresh = function(self, event, target, player, data)
      return player.dead and player:hasSkill(yechou.name, true, true) and data.damage and data.damage.card and
      table.contains(data.damage.card.skillNames, yechou.name) and player:getMark("heg__yechou-target") == target.id
    end,
    on_refresh = function(self, event, target, player, data)
      local room = player.room
      room:notifySkillInvoked(player, yechou.name)
      player:broadcastSkillInvoke(yechou.name)
      room:addPlayerMark(target, yechou.name)
      room.logic:getCurrentEvent():findParent(GameEvent.Dying, true):addExitFunc(function ()
      room:removePlayerMark(target, yechou.name)
      end)
    end,
})

yechou:addEffect("prohibit",{
    prohibit_use = function(self, player, card)
    if card.name == "peach" and not player.dying then
      return table.find(Fk:currentRoom().alive_players, function(p)
        return p.dying and p:getMark(yechou.name) > 0 and H.compareKingdomWith(p, player)
      end)
    end
  end,
})

yechou:addEffect(fk.TargetSpecified,{
    mute = true,
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(yechou.name, false, true) and (data.extra_data or {}).heg__yechoutarget == data.to.id
        and (data.extra_data or {}).qinggang
    end,
    on_use = function (self, event, target, player, data)
        data.to:addQinggangTag(data)
    end,
})

return yechou